package com.steven.sync;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * 就像田径长跑，每10个人以组，到是个人了，发令枪响，然后在等10个人，在发令枪响
 */
public class CyclicBarrier_test {

    public static void main(String[] args) {
        CyclicBarrier barrier = new CyclicBarrier(20,()->{
            System.out.println("人满到了：biu----");
        });

        for (int i = 0; i < 100; i++) {

            new Thread(()->{
                try {
                    System.out.println(Thread.currentThread().getName());
                    barrier.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (BrokenBarrierException e) {
                    e.printStackTrace();
                }
            }).start();
        }

    }


}
